/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.unesp.demac.soo.dao;

import br.unesp.demac.bcc.soo.bean.Login;
import br.unesp.demac.soo.util.FabricaConexao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author flavioam
 */
public class LoginDAOImp implements LoginDAO {

    @Override
    public boolean autenticacao(Login l) {

        boolean autenticated = false;
        Connection con = null;

        try {

            con = FabricaConexao.getConexao();

            String sql = "select * from Logins where usuario = ?";

            PreparedStatement pstmt = con.prepareStatement(sql);

            pstmt.setString(1, l.getUsuario());

            ResultSet rs = pstmt.executeQuery();

            if (rs.next()) {

                String senha = rs.getString("senha");

                if (senha.equals(l.getSenha())) {

                    autenticated = true;
                }
            }

        } catch (SQLException e) {

            throw new Exception(e.getMessage());

        } catch (Exception e) {

            throw new Exception(e.getMessage());

        } finally {
            FabricaConexao.fechar(con);
            return autenticated;
        }
    }
    
    
}
